public class StudentTest {
    public static void main(String[] args) {
        Student[] arr = new Student[3];
        Student s1 = new Student(2113, "张三", 12);

        Student s2 = new Student(21113, "李四", 45);
        Student s3 = new Student(21113, "王四", 5);
        arr[0] = s1;
        arr[1] = s2;
        arr[2] = s3;

        Student s4 = new Student(1234567, "赵六", 46);
        //把s4添加到数组中,数组满了扩容
        boolean flag = contians(arr, s4.getId());
        if (flag) {
            System.out.println("id重复请重新输入:");
        } else {
            //数组满了
            int count = getCount(arr);
            if (count == arr.length) {
                //创建新数组
                Student[] newArr = new Student[arr.length+1];
                newArr = createArr(arr,newArr);
                newArr[count]  = s4;
                getPrint(newArr);
            } else {
                //数组没满
                arr[count] = s4;
                getCount(arr);
            }
        }


    }

    public static boolean contians(Student[] arr, int id) {

        for (int i = 0; i < arr.length; i++) {
            int sid = arr[i].getId();
            if (sid == id) {
                return true;
            }
        }
        return false;
    }

    public static int getCount(Student[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                count++;
            }
        }
        return count;
    }

    public static Student[] createArr(Student[] arr,Student[] newArr) {

        for (int i = 0; i < arr.length; i++) {
                newArr[i] = arr[i];
        }
        return newArr;
    }

    public static void getPrint(Student[] arr) {
        for (int i = 0; i < arr.length; i++) {
           Student a = arr[i];
            System.out.println(a.getId()+", "+a.getAge()+", "+a.getName());
        }
    }
}
